// partial 把类型全部变为可选的的

import { IAnimal } from "./typeings"
// interface IAnimal {
//     type: string
//     huidong:boolean
//     run: ()=> void
// }

// keyof T => type
type MyPartial<T> = {
    [K in keyof T]: T[K]
}

class Tiger implements Partial<IAnimal> {
    type = '猫科动物'
    run():string{
        return '我会跑'
    }
}

type MyRequired<T>={
    [K in keyof T]-?:T[K]
}
class Cat implements MyRequired<MyPartial<IAnimal>> {
    type = '猫科动物'
    huidong=true
    run():string{
        return '我会跑'
    }
}

// Readonly 把类型全部变成只读
interface IObj {
    name:string
    age:number
    sex:'女'
}

// type MyReadonly = Readonly<IObj>
type MyReadonly<T> ={
    readonly [K in keyof T]:T[K]
}

const obj:MyReadonly<IObj> = {
    name:'邓紫棋',
    age : 22,
    sex :'女'
}

// obj.name= '刘亦菲'
console.log(obj);

// pick摘取，从一个对象类中摘取部分类型成为一个新的类型
interface Todo {
    title:string;
    description:string;
    comleted:boolean
}

// Record<keys,type> 构造一个对象类型
interface CatInfo {
    age: number
    breed: string
}

type CatName = "miffy" | "boris" | "mordred";

const cats:Record<CatName,CatInfo> = {
    miffy: {age:10,breed:"Persian"},
    boris: {age:5,breed:"Maine Coon"},
    mordred: {age:10,breed:"British Shorthair"},
}

interface Todo {
    title: string;
    description:string
    completed:boolean
}

type TodoPreview = Pick<Todo,'title' | 'completed'>

const obj1: TodoPreview = {
    completed: true,
    title: 'test'
}
